package com.example.demo.leetcode.codetop.bytedance;

/**
 * @author xujimou
 * @version 2.0
 * @Description
 * @date 2022/2/23 16:04
 */
public class 翻转链表 {


    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    /**
     * @Desciption:
     *
     *  null  1 ->  2  -> 3 -> null
     *   pre  head next
     *
     * @param head:
     */
    public ListNode reverseList(ListNode head) {

        ListNode pre = null;
        while(head != null){
            ListNode next = head.next;
            head.next = pre;
            pre = head;
            //结束
            head = next;
        }
        return pre;
    }
}
